import config from 'config'
import httpFetch from 'share/httpFetch'
import errorMessage from 'share/errorMessage'
import {messages} from "share/common";
import {message} from "antd/lib/index";

export default {
  /**
   * 分配机票任务
   * @param targetBookerOID
   * @param params
   * @returns {*}
   */
  deliveryTicket(targetBookerOID, params) {
    return httpFetch.post(`${config.baseUrl}/api/travel/operation/transferApply?targetBookerOID=${targetBookerOID}`, params)
  },
  getTraveList(page, size, params) {
    return httpFetch.post(`${config.baseUrl}/api/travel/operation/records?page=${page}&size=${size}`, params)
  },
  getTransferPersons() {
    return httpFetch.get(`${config.baseUrl}/api/account/get/users/V2/ROLE_COMPANY_BOOK?roleType=TENANT`)
  },
  //获取订票专员列表
  //type: 1003（订票申请）
  getCommissionerList(params, searchParams) {
    params = Object.assign({}, params, searchParams);
    return httpFetch.get(`${config.baseUrl}/api/travel/operation/records`, params)
  },
  //导出订票专员数据
  exportCommissionerData(startDate, endDate) {
    let params = {};
    endDate && (params.endDate = endDate);
    startDate && (params.startDate = startDate);
    return new Promise((resolve, reject) => {
      httpFetch.get(`${config.baseUrl}/api/travel/book/orders/export`, params, {}, {responseType: "arraybuffer"}).then(res => {
        resolve(res)
      }).catch(e => {
        errorMessage(e.response);
        reject(e)
      })
    })
  },
  //获取订票信息详情
  getBookingDetail(params) {
    // ?oldFunction=${oldFunction}&${apoid}travelOperationRecordOIDs=${travelOperationRecordOID}
    return httpFetch.get(`${config.baseUrl}/api/travel/booker/order`, params)
  },

  //批量获取用户详情
  getApplicantName(userOIDs) {
    return httpFetch.post(`${config.baseUrl}/api/v2/users/oids`, userOIDs)
  },

  getFuntionProfile() {
    let profile = sessionStorage.getItem("functionProfile");
    if (profile) {
      httpFetch.get(`${config.baseUrl}/api/function/profiles`)
        .then(function (data) {
          sessionStorage.setItem("functionProfile", data);
          if (data["sys.language.default"]) {
            sessionStorage.setItem("sysLanguageDefault", data["sys.language.default"].toLowerCase());
          } else {
            sessionStorage.setItem("sysLanguageDefault", "zh_cn");
          }
        });
      return new Promise(function (resolve) {
        resolve(profile);
      });
    } else {
      return new Promise(function (resolve) {
        httpFetch.get(`${config.baseUrl}/api/function/profiles`)
          .then(function (data) {
            resolve(data);
            sessionStorage.setItem("functionProfile", data);
            if (data["sys.language.default"]) {
              sessionStorage.setItem("sysLanguageDefault", data["sys.language.default"].toLowerCase());
            } else {
              sessionStorage.setItem("sysLanguageDefault", "zh_cn");
            }
          })
      });
    }
  },
  getMyCompanyConfiguration() {
    // let configuration = sessionStorage.getItem("company.configuration");
    // if (0) {
    //   console.log(configuration);
    //   return new Promise(function (resolve) {
    //     resolve(configuration);
    //   });
    // } else {
    //
    // }
    return new Promise(function (resolve, reject) {
      httpFetch.get(`${config.baseUrl}/api/company/configurations/user`)
        .then(function (data) {
          sessionStorage.setItem("company.configuration", data);
          resolve(data);
        }).catch(e => {
        reject(e);
      })
    });
  },
  //获取法人实体
  getCompanyInvoice(companyInvoiceOID) {
    return httpFetch.get(`${config.baseUrl}/api/my/company/receipted/invoice/${companyInvoiceOID}`)
  },
  //银行卡详情
  getBankAccountDetail(contactBankAccountOID) {
    return httpFetch.get(`${config.baseUrl}/api/contact/bank/account/${contactBankAccountOID}`)
  },
  getItem(costCenterItemOID) {
    return httpFetch.get(`${config.baseUrl}/api/cost/center/item/${costCenterItemOID}`)
  },
  //查询部门详情
  getDepartmentInformation(departmentOID) {
    return httpFetch.get(`${config.baseUrl}/api/departments/${departmentOID}`)
  },
  //获取值列表描述详情
  getCustomValueDetail(customEnumerationOID) {
    return httpFetch.get(`${config.baseUrl}/api/custom/enumerations/${customEnumerationOID}/simple`)
  },
  getCustomValueItemDetail(dataFrom, customEnumerationOID, value) {
    //dataFrom  102  外部值列表
    if (dataFrom === 102) {
      return httpFetch.get('/api/custom/enumerations/items/out', {
        params: {
          customEnumerationOID: customEnumerationOID,
          messageKey: value
        }
      });
    } else {
      return httpFetch.get('/api/custom/enumerations/items', {
        params: {
          customEnumerationOID: customEnumerationOID,
          messageKey: value
        }
      });
    }
  },
  updateOrder(noticeUser, data, params) {
    const {oldFunction, travelBookerApplicationId} = params;
    const travelId = `&travelBookerApplicationId=${travelBookerApplicationId}`;
    return httpFetch.post(`${config.baseUrl}/api/travel/book/orders/addOrUpdate?noticeUser=${noticeUser}&oldFunction=${oldFunction}${travelId}`, data);
  },
  //通知申请人确认机票信息
  notifyApplicant(applicationOID) {
    return httpFetch.get(`${config.baseUrl}/api/travel/operation/confirm/submit?applicationOID=${applicationOID}`);
  },
  //发起价格审核
  launchPriceApproval(applicationOID) {
    return httpFetch.get(`${config.baseUrl}/api/travel/operation/priceAudit/submit?applicationOID=${applicationOID}`);
  },
  //通知乘机人机票信息
  notifyPassenger(params, userOIDs) {
    const {applicationOID, oldFunction, travelBookerApplicationId} = params;
    const apoid = (applicationOID && applicationOID != 'null') ? `&applicationOID=${applicationOID}` : '';
    const travelId = `&travelBookerApplicationId=${travelBookerApplicationId}`;
    return httpFetch.post(`${config.baseUrl}/api/travel/operation/records/notice?oldFunction=${oldFunction}${apoid}${travelId}`, userOIDs);
  },
  //删除出行机票订单
  deleteTravelOrder(travelOrderOID) {
    return httpFetch.get(`${config.baseUrl}/api/travel/book/orders/delete/?travelOrderOID=${travelOrderOID}`);
  },
  //退票
  refundTravelOrder(data, params) {
    const {oldFunction, travelBookerApplicationId} = params;
    const travelId = `&travelBookerApplicationId=${travelBookerApplicationId}`;
    return httpFetch.post(`${config.baseUrl}/api/travel/book/orders/refund?oldFunction=${oldFunction}${travelId}`, data);
  },
  //乘机人默认证件号
  getDefaultCards(userOID) {
    return httpFetch.get(`${config.baseUrl}/api/contact/cards/default?userOID=${userOID}`);
  },
  handOperation(travelOperationRecordOID) {
    return httpFetch.get(`${config.baseUrl}/api/travel/operation/handed?travelOperationRecordOID=${travelOperationRecordOID}`);
  },
  /**
   * 获取机票供应商
   * @returns {*}
   */
  travelSuppliers() {
    return httpFetch.get(`${config.baseUrl}/api/suppliers/2001`);
  },

  /**
   * 新获取订票信息
   * @param id
   * @returns {*}
   */
  getOrderTicketInfo(id) {
    return httpFetch.get(`${config.baseUrl}/api/travel/booker/application/${id}`);
  },


}
